# -*- coding : utf-8 -*-
# @Time      : 2020/10/8 13:54
# @Author    : 小公瑾
# @email     : ziyu.liu@i9i8.com
# @FileName  : heliumtest.py
# @Software  : PyCharm
from time import sleep

from helium import *
from selenium.webdriver import ChromeOptions

# 浏览器配置
options = ChromeOptions()
options.add_argument('--start-maximized')
options.add_argument('--proxy-server=socks5://192.168.2.66:9005')

# 全局配置：设置隐形等待时间为30秒
Config.implicit_wait_secs = 30

# 因为helium是基于selenium做了二次封装，因而可以将selenium与helium结合使用
start_chrome('https://www.azazie.com/', options=options)

# 切换到selenium
driver = get_driver()
# driver.execute_script()


# 大转盘处理
def big_wheel_handler():

    close_wheel_btn = S("[title='Close']")
    wait_until(Text('Your Special Bonus Offer Has Been Unlocked!!').exists)
    try:
        click(close_wheel_btn)
    except LookupError:
        pass


big_wheel_handler()
wait_until(Text('Sign In').exists)

click("Sign In")

# 登录
wait_until(Text('Sign In').exists)
write('autotest@tetx.com', S('#_email'))
write('123456', S('#_password'))
# 高亮标记
highlight(S('.btn.btn-theme.btn-user-form', below='OR LOGIN WITH EMAIL'))
sleep(3)
click(S('.btn.btn-theme.btn-user-form', below='OR LOGIN WITH EMAIL'))
sleep(3)

# 注意：这里是直接在当前窗口访问指定的url（原页面会被覆盖），不会重新打开浏览器也不会新开一个页签去访问
go_to('https://www.baidu.com/')

li = find_all(Window())
print(li)
# 页面标题
print(Window().title)
# 窗口句柄
print(Window().handle)

# 获取元素的属性值
value = S('#su').web_element.get_attribute('value')
print(value)

# 获取元素的属性值
value2 = Text(S('#su')).value
print(value2)

# 获取元素的文本值
txt = S('#u1 > span').web_element.text
print(txt)
# 获取元素的标签名
tag = S('#u1 > span').web_element.tag_name
print(tag)


sleep(3)
# 关闭浏览器
kill_browser()


class Test:

    __slots__ = ['name', 'age', 'hobby']

    def __init__(self, name, age, hobby):
        self.name = name
        self.age = age
        self.hobby = hobby
